<! Controller -->
<?php
	require_once ('../../models/Users.php');
	session_start();
	$response = Users::GetAll();
?>

<! View -->
<!DOCTYPE html>
<html lang="en">
	<?php include('../../inc/head.php'); ?>
	<body>
		<div>
			<?php include('../../inc/nav.php'); ?>

				
			<div id="content">
				<? if(isset($_GET['inserted'])): ?>
					<div class="alert alert-success">
   						 <button type="button" class="close">×</button>
    				 	A user has been successfully added.
    				</div>
    			<? endif; ?>
				<a href="edit.php">+ Create New</a>
				
				<table class = "table table-bordered table-condensed table-hover table-striped">
					<tr>
						<th>First Name</th><th>Last Name</th><th>Keyword ID</th><th>Actions</th>
					</tr>
					
					<?php while($row = $response->fetch_assoc()): ?>
						<tr class="<?= isset($_GET['inserted']) && $row['id'] == $_GET['inserted'] ? 'error' : '' ?>">
							<td><?=$row['FirstName']?></td>
							<td><?=$row['LastName']?></td>
							<td><?=$row['Name']?></td>
							<td>
								<a href="details.php?id=<?=$row['id']?>">Details</a>
								<a href="edit.php?id=<?=$row['id']?>" class="edit-link">Edit</a>
								<a href="delete.php?id=<?=$row['id']?>" class="delete-link">Delete</a>
							</td>				
						</tr>
					<?php endwhile; ?>
					
					<tr>
						<td><a href="create.php">Insert</a></td>
					</tr>
				
				</table>
			</div>
				<?php include('../../inc/footer.php'); ?>
			</div>
		</div>
		    <div id="delete-box" class="modal hide fade">
    	<div class="modal-header">
    		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    		<h3>Delete</h3>
    	</div>
    	<div class="modal-body">
    	</div>
    	
    	</div>
		    <div id="edit-box" class="modal hide fade">
    	<div class="modal-header">
    		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    		<h3>Edit</h3>
    	</div>
    	<div class="modal-body">
    	</div>
    	
    	 <script type="text/javascript" src="../../static/js/bootstrap.js"></script>
         <script type="text/javascript">
         	$(function(){
            	$(".close").click(function(){
                   	$(this).closest(".alert").slideUp();
                });
                $(".error").removeClass('error', 'slow');
                $(".delete-link").click(function(){
                   	$("#delete-box").modal({'show':true });
                   	$.get(this.href, function(data){
                   		$("#delete-box").find(".modal-body").html($(data).find("form"));
                   	});
                    return false;
                });
                
                $(".edit-link").click(function(){
                   	$("#edit-box").modal({'show':true });
                   	$.get(this.href, function(data){
                   		$("#edit-box").find(".modal-body").html($(data).find("form"));
                   	});
                    return false;
                });
            });
         </script>

	</body>
</html>
